package com.kun.portal.webframe.controller;
import com.kun.portal.webframe.po.FwUserPo;
import com.kun.portal.webframe.po.MessagePushPo;
import com.kun.portal.webframe.service.MessagePushService;
import com.kun.portal.webframe.util.UserSessionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.format.datetime.DateFormatter;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2018-09-10.
 *
 * 消息推送
 */
@Controller
@RequestMapping({"/api/mgp"})
public class MessagePushController {
    @Autowired
    private MessagePushService messagePushService;
    @InitBinder
    public void intDate(WebDataBinder dataBinder){
        dataBinder.addCustomFormatter(new DateFormatter("yyyy-MM-dd"));
    }
    @RequestMapping(
            value = {"/findAllMp"},
            method = {RequestMethod.GET},
            produces = {"application/json"}

    )
    @ResponseBody
    public Page<MessagePushPo> findMpByMgType(Pageable pageable, String mgType, Boolean handle, String mgContent){
        return messagePushService.findMg(mgType,handle,mgContent,pageable);
    }
    @RequestMapping(
            value = {"/saveMp"},
            method = {RequestMethod.POST},
            produces = {"application/json"}
    )
    @ResponseBody
    public void saveMp(@RequestBody MessagePushPo messagePushPo, HttpSession session){
        FwUserPo user = UserSessionUtil.getCurrentUser(session);
        messagePushPo.setHandelUser(user);
        messagePushService.saveMp(messagePushPo);
    }
    @RequestMapping(
            value = {"/findNotHandelMg"},
            method = {RequestMethod.GET},
            produces = {"application/json"}
    )
    @ResponseBody
    public Long findNotHandelMg(Boolean handle,String mgType){
        return messagePushService.findNotHandelMg(handle,mgType);
    }


}
